package com.winiex.javamultithread;

public class CreateThreadInRunMethod extends Thread{
	private Object lock1 = new Object();
	private Object lock2 = new Object();
	private Object lock3 = new Object();
	
	private String data1 = null;
	private String data2 = null;
	private String data3 = null;
	
	@Override
	public void run() {
		super.run();
		Thread thread1 = new Thread() {

			@Override
			public void run() {
				synchronized (lock1) {
					data1 = "data1";
					lock1.notifyAll();
				}
			}
			
		};
		thread1.start();
		
		synchronized (lock1) {
			while (thread1.isAlive() && data1 == null) {
				try {
					lock1.wait();
				} catch (Exception e) {
				}
			}
		}
		
		System.out.println(data1);
		
		Thread thread2 = new Thread() {

			@Override
			public void run() {
				synchronized (lock2) {
					data2 = "data2";
					lock2.notifyAll();
				}
			}
			
		};
		thread2.start();
		
		synchronized (lock2) {
			while (thread2.isAlive() && data2 == null) {
				try {
					lock2.wait();
				} catch (Exception e) {
				}
			}
		}
		
		System.out.println(data2);
		
		Thread thread3 = new Thread() {

			@Override
			public void run() {
				synchronized (lock3) {
					data3 = "data3";
					lock3.notifyAll();
				}
			}
			
		};
		thread3.start();
		
		synchronized (lock3) {
			while (thread3.isAlive() && data3 == null) {
				try {
					lock3.wait();
				} catch (Exception e) {
				}
			}
		}
		
		System.out.println(data3);
		
	}
	
	public static void main(String[] args) {
		new CreateThreadInRunMethod().start();
	}
}
